<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <!-- 满足有些用户在手机端访问的需要 -->

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">

    <title>用户管理</title>
    <!-- 线上环境 -->
    <link rel="stylesheet" href="/static/css/dist/component-min.css">
    <link rel="stylesheet" href="/static/plugins/jbox/jbox-min.css">

    <!--vue-->
    <script src="/static/vue/vue.js"></script>
    <!--element ui-->
    <script src="/static/element/index.js"></script>
    <link rel="stylesheet" href="/static/element/index.css">
    <style>
        .el-table__empty-block {
            height: 0;
        }
    </style>

</head>
<body class="cp-bodybox">
<div id="app">
    <#include "/common/header-fg.html" />

    <div class="container">
        <div class="inner clearfix">
            <#include "/common/left-menu-fg.html" />

            <div class="content-right">
                <h1 class="content-right-title">抽奖管理</h1>
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span style="line-height: 36px;">筛选区</span>
                        <div style="float: right">
                            <el-button type="primary" @click.native.prevent="getList">查询</el-button>
                            <el-button type="primary" @click.native.prevent="clearSearch">清空查询条件</el-button>
                        </div>
                    </div>
                    <el-form :inline="true" ref="search" :model="search" label-width="80px">
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="活动名">
                                    <el-input v-model="search.name" placeholder="名称"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="有效时间">
                                    <el-date-picker
                                            v-model="search.startTime"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>&nbsp;至&nbsp;
                                    <el-date-picker
                                            v-model="search.endTime"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item label="状态">
                                    <el-select v-model="search.enable" placeholder="请选择状态">
                                        <el-option label="启用" value="1"></el-option>
                                        <el-option label="禁用" value="0"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-card>
                <el-card class="box-card" style="margin-top: 10px">
                    <div slot="header" class="clearfix">
                        <span style="line-height: 36px;">抽奖信息列表</span>
                        <el-button type="primary" style="float: right;" v-if="isPermission('lottery:add', user.permissions)" @click.native="add">添加</el-button>
                    </div>
                    <el-table
                            :data="luckList"
                            border
                            style="width: 100%">
                        <el-table-column
                                type="index"
                                label="序号"
                                width="80">
                        </el-table-column>
                        <el-table-column
                                prop="id"
                                label="ID">
                        </el-table-column>
                        <el-table-column
                                prop="name"
                                label="活动">
                        </el-table-column>
                        <el-table-column
                                prop="startTime"
                                label="开始时间"
                                align="center"
                                :formatter="formatterTime"
                                width="130">
                        </el-table-column>
                        <el-table-column
                                prop="endTime"
                                label="结束时间"
                                align="center"
                                :formatter="formatterEndTime"
                                width="130">
                        </el-table-column>
                        <el-table-column
                                prop="enable"
                                label="状态"
                                :formatter="formatterStatus">
                        </el-table-column>
                        <el-table-column
                                prop="joinManTotal"
                                label="参与人数"
                                :formatter="formatterJoinManTotal">
                        </el-table-column>
                        <el-table-column
                                prop="joinTotal"
                                label="参与次数"
                                :formatter="formatterJoinTotal">
                        </el-table-column>
                        <!--<el-table-column-->
                                <!--prop="winTotal"-->
                                <!--label="领奖人数"-->
                                <!--:formatter="formatterWinTotal">-->
                        <!--</el-table-column>-->
                        <el-table-column
                                align="center"
                                label="操作"
                                inline-template>
                            <div style="margin-left: -10px">
                                <el-dropdown>
                                    <el-button size="small" type="primary">
                                        操作<i class="el-icon-caret-bottom el-icon--right"></i>
                                    </el-button>
                                    <el-dropdown-menu slot="dropdown" align="center">
                                        <el-dropdown-item v-if="isPermission('lottery:enable', user.permissions)">
                                            <el-button size="mini" type="primary" v-if="row.enable === 0" class="el-icon-edit" @click.native.prevent="enable(row.id, 1)">启用</el-button>
                                            <el-button size="mini" type="primary" v-else class="el-icon-edit" @click.native.prevent="enable(row.id, 0)">禁用</el-button>
                                        </el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('lottery:winList', user.permissions)"><el-button size="mini" type="primary" class="el-icon-edit" @click.native.prevent="detail(row.id)">详情</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('lottery:edit', user.permissions)"><el-button size="mini" type="primary" class="el-icon-edit" @click.native.prevent="edit(row.id)">编辑</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('lottery:delete', user.permissions)"><el-button size="mini" type="primary" class="el-icon-edit" @click.native.prevent="confirmDelete(row.id)">删除</el-button></el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </div>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                            @current-change="handleCurrentPageChange"
                            :current-page="currentPage"
                            :page-size="pageSize"
                            layout="total, prev, pager, next"
                            :total="totalCount">
                    </el-pagination>
                </el-card>
            </div>
            <!-- end content-right -->

            <a href="javascript:;" class="btn-leftMenuFold" id="j-btn-leftMenuFold"></a>
        </div>
    </div>
    <!-- end container -->

    <!--gonggao-->

    <!--tip-->
    <div class="footer">© 2017 , Inc. All rights reserved.</div>
    <!-- end footer -->
    <div class="fixedBar" style="right: -78px;">
        <ul>
            <template v-for="(item, index) in leftMenuList">
                <li v-if="index==0" :class="'shopManager' + index + ' cur'"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
                <li v-else :class="'shopManager' + index"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
            </template>
        </ul>
        <a href="javascript:;" class="fixedBar-btn" id="j-fixedBar-btn"></a>
    </div>
    <a href="#" id="j-gotop" class="gotop" title="回到顶部" style="left: 1920.59px;"></a>

</div>
<script src="/static/js/dist/lib-min.js"></script>
<script src="/static/js/dist/list.js"></script>
<script src="/static/js/dist/component-min.js"></script>

<!-- 引入api -->
<script src="/static/js/api.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function(){
            return {
                user: ${(user)!'null'},
                headerNavList: list.headerNavList,
                form: {
                    resource: 1,
                    desc: ''
                },
                accountNavList: list.accountNavList,
                leftMenuList: list.menu,
                search: {
                    startTime: '',
                    endTime: '',
                    name: '',
                    enable: ''
                },
                luckList: [],
                currentPage: list.currentPage,
                pageSize: list.pageSize,
                totalCount: 0
            }
        },
        mounted:function () {
            this.getList ();
        },
        methods: {
            enable (id, value) {
                let that = this
                let obj = {
                    id: id
                }
                let url = value?'/lottery/enable':'/lottery/disable'
                this.http(url,obj,function (res) {
                    if(res.status === 200){
                        that.getList()
                    }else{
                        that.$alert(res.errMsg,'提示',{
                            confirmButtonText:'确定',
                        })
                    }
                },function (res) {
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            formatterTime (row, column) {
                if (row.startTime !== undefined && (row.startTime + "").length >= 10) {
                    return (row.startTime + "").substring(0, 10);
                } else {
                    return row.startTime;
                }
            },
            formatterEndTime (row, column) {
                if (row.endTime !== undefined && (row.endTime + "").length >= 10) {
                    return (row.endTime + "").substring(0, 10);
                } else {
                    return row.endTime;
                }
            },
            formatterStatus(row){
                if (row.enable === 1) {
                    return '启用'
                } else if (row.enable === 0) {
                    return '禁用'
                }
            },
            formatterJoinManTotal(row){
                if (row.joinManTotal === undefined || row.joinManTotal === '') {
                    return '0'
                } else {
                    return row.joinManTotal
                }
            },
            formatterJoinTotal(row){
                if (row.joinTotal === undefined || row.joinTotal === '') {
                    return '0'
                } else {
                    return row.joinTotal
                }
            },
            formatterWinTotal(row){
                if (row.winTotal === undefined || row.winTotal === '') {
                    return '0'
                } else {
                    return row.winTotal
                }
            },
            handleCurrentPageChange(val) {
                this.currentPage = val
            },
            add () {
                window.location.href = '/luck/add'
            },
            detail (id) {
                window.location.href = '/luck/detail?id=' + id
            },
            edit (id) {
                window.location.href = '/luck/add?id=' + id
            },
            delete (id) {
                let that = this
                let obj = {
                    id: id
                }
                this.http('/lottery/delete',obj,function (res) {
                    if(res.status === 200){
                        that.getList()
                    }else{
                        that.$alert(res.errMsg,'提示',{
                            confirmButtonText:'确定',
                        })
                    }
                },function (res) {
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            confirmDelete (id) {
                let that = this;
                this.$confirm('此操作将删除该活动, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    that.delete(id);
                }).catch(function () {
                    that.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            getList () {
                let that = this
                let obj = {}
                obj.currentPage = this.currentPage
                obj.pageSize = this.pageSize
                if (this.search.name != '') {
                    obj.name = this.search.name
                }
                if (this.search.enable != '') {
                    obj.enable = this.search.enable
                }
                if (this.search.startTime != '') {
                    obj.startTime = this.formatTime(this.search.startTime, true)
                }
                if (this.search.endTime != '') {
                    obj.endTime = this.formatTime(this.search.endTime, true)
                }
                let loading = this.$loading({fullscreen: true, lock: true, text: '加载中'});
                this.http('/lottery/list',obj,function (res) {
                    if(res.status === 200){
                        that.luckList = res.data.list;
                        that.totalCount = res.data.total;
                        loading.close();
                    }else{
                        loading.close();
                        that.$alert('服务器错误','提示',{
                            confirmButtonText:'确定',
                        })
                    }
                },function (res) {
                    loading.close();
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            clearSearch () {
                this.search.name = ''
                this.search.enable = ''
                this.search.startTime = ''
                this.search.endTime = ''
                this.currentPage = 1
                this.getList()
            }
        }
    })
</script>

<!-- 20170105 --></body>
</html>